package com.sise.netty.手写Tomcat;

import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

/**
 * 请求
 *
 * @author idea
 * @data 2019/4/25
 */
@Data
public class MyRequest {

    private String url;

    private String method;

    public MyRequest(InputStream inputStream) throws IOException {
        String httpRequest = "";
        byte[] httpRequestBytes = new byte[1024];
        int length = 0;
        if ((length = inputStream.read(httpRequestBytes)) > 0) {
            httpRequest = new String(httpRequestBytes, 0, length);
        }

        String httpHead = httpRequest.split("\n")[0];
        System.out.println("[httphead]"+httpHead);
        String[] httpContentArr=httpHead.split("\\s");
        if(httpContentArr.length>0){
            method = httpHead.split("\\s")[0];
            url = httpHead.split("\\s")[1];
        }
        System.out.println(this);
    }
}
